#
# @lc app=leetcode.cn id=121 lang=python3
#
# [121] 买卖股票的最佳时机
#

# @lc code=start
class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        n = len(prices)
        cost = prices[0]
        profit = 0
        for i in range(0, n):
            cost = min(cost, prices[i])
            profit = max(profit, prices[i]-cost)
        
        return profit
        

# @lc code=end

